﻿//bgDate : 租赁开始日期
//endDate： 租赁结束日期
//rentMoney: 月租金
//type : 1=住宅 2=非住宅
var fcRat = 0; //房产税
var GrRat = 0; //个人所得税
var jszje = 0; //税金
var totalRent=0 //计税总额
function getRatMoney(bgDate, endDate, rentMoney, type) {
    var dtBegin = new Date(bgDate);
    var dtEnd = new Date(endDate);

    var bgDay = dtBegin.getDate();
    var endDay = dtEnd.getDate();

    //计算税收月份
    var diff = 0;
    var dayDiff = endDay - bgDay + 1;
    if (dayDiff < -15) {
        diff = -1;
    } else if (dayDiff >= 15) {
        diff = 1;
    } else {
        diff = 0;
    }

    var yearsDif = dtEnd.getFullYear() - dtBegin.getFullYear();
    var monthDif = dtEnd.getMonth() - dtBegin.getMonth()  + yearsDif * 12 + diff;
        totalRent = monthDif * rentMoney; //计算月份*月租
    switch (type) {

        case "1":
            
            if (rentMoney >= 0 && rentMoney <= 20000)
            {

                fcRat = totalRent * 0.04;
                GrRat = 0.00;
                jszje = fcRat + GrRat;
            }
               
            else if (rentMoney > 20000 && rentMoney <= 31500)
            {
                fcRat = totalRent * 0.04;
                GrRat = totalRent * 0.08;
                jszje = fcRat + GrRat;
            }
            else
            {
                fcRat = 0.00;
                GrRat = 0.00;
                jszje = fcRat + GrRat;
            }
            break;
        case "2":
          
            if (rentMoney > 0 && rentMoney <= 20000)
            {
                fcRat = totalRent * 0.12;
                GrRat = 0.00;
                jszje = fcRat + GrRat;
            }
            
            else if (rentMoney > 20000 && rentMoney <= 31500)
            {
                fcRat = totalRent * 0.12;
                GrRat = totalRent * 0.01;              
                jszje = fcRat + GrRat;
            } else
            {
                GrRat = 0.00;
                fcRat = 0.00;
                jszje = fcRat + GrRat;
            }
            break;
    }

}






